﻿#include "ThreeDCloudMapSettingData.h"
#include "ScalarBarSettingData.h"
#include "BaseModule/GlobalHelper.h"
namespace pst
{
    ThreeDCloudMapSettingData::ThreeDCloudMapSettingData(QObject* parent, int id)
        : QObject(parent)
        , m_scalarBarSettingData(nullptr)
        , m_geometrySettingData(nullptr)
        , m_resultDataSettingData(nullptr)
        , m_id(id)
        , m_cubeAxesActorSettingData(nullptr)
    {
    }

    ThreeDCloudMapSettingData::~ThreeDCloudMapSettingData()
    {
    }

    int ThreeDCloudMapSettingData::getID() const
    {
        return m_id;
    }

    void ThreeDCloudMapSettingData::setScalarBarSettingData(ScalarBarSettingData* scalarBarSettingData)
    {
        m_scalarBarSettingData = scalarBarSettingData;
    }

    ScalarBarSettingData* ThreeDCloudMapSettingData::getScalarBarSettingData() const
    {
        return m_scalarBarSettingData;
    }

    void ThreeDCloudMapSettingData::setGeometrySettingData(TDCMGeometrySettingData* TDCMGeometrySettingData)
    {
        m_geometrySettingData = TDCMGeometrySettingData;
    }

    TDCMGeometrySettingData* ThreeDCloudMapSettingData::getGeometrySettingData() const
    {
        return m_geometrySettingData;
    }

    void ThreeDCloudMapSettingData::setResultDataSettingData(TDCMResultDataSettingData* TDCMResultDataSettingData)
    {
        m_resultDataSettingData = TDCMResultDataSettingData;
    }

    TDCMResultDataSettingData* ThreeDCloudMapSettingData::getResultDataSettingData() const
    {
        return m_resultDataSettingData;
    }

    void ThreeDCloudMapSettingData::setCubeAxesActorSettingData(TDCMCubeAxesActorSettingData* cubeAxesActorSettingData)
    {
        m_cubeAxesActorSettingData = cubeAxesActorSettingData;
    }

    TDCMCubeAxesActorSettingData* ThreeDCloudMapSettingData::getCubeAxesActorSettingData()
    {
        return m_cubeAxesActorSettingData;
    }

    QDomElement& ThreeDCloudMapSettingData::writeToProjectFile(QDomDocument* doc, QDomElement* element, bool isdiso)
    {
        QDomElement _ThreeDCloudMapSettingDataRoot = doc->createElement("ThreeDCloudMapSettingData");
        QDomAttr idattr = doc->createAttribute("CloudMapSettingDataID");
        idattr.setValue(QString::number(m_id));
        _ThreeDCloudMapSettingDataRoot.setAttributeNode(idattr);

        if (m_scalarBarSettingData != nullptr)
            m_scalarBarSettingData->writeToProjectFile(doc, &_ThreeDCloudMapSettingDataRoot, isdiso);
        if (m_geometrySettingData != nullptr)
            m_geometrySettingData->writeToProjectFile(doc, &_ThreeDCloudMapSettingDataRoot, isdiso);
        if (m_resultDataSettingData != nullptr)
            m_resultDataSettingData->writeToProjectFile(doc, &_ThreeDCloudMapSettingDataRoot, isdiso);
        if (m_cubeAxesActorSettingData != nullptr)
            m_cubeAxesActorSettingData->writeToProjectFile(doc, &_ThreeDCloudMapSettingDataRoot, false, isdiso);

        element->appendChild(_ThreeDCloudMapSettingDataRoot);

        return _ThreeDCloudMapSettingDataRoot;
    }

    void ThreeDCloudMapSettingData::readFromProjectFile(QDomElement* element, bool isdiso)
    {
        m_id = element->attribute("CloudMapSettingDataID").toInt();
        auto _ScalarBarSettingDataEle = element->elementsByTagName("ScalarBarSettingData");
        auto _TDCMGeometrySettingDataEle = element->elementsByTagName("TDCMGeometrySettingData");
        auto _TDCMResultDataSettingDataEle = element->elementsByTagName("TDCMResultDataSettingData");
        auto _TDCMCubeAxesActorSettingDataeEle = element->elementsByTagName("TDCMCubeAxesActorSettingData");

        if (m_scalarBarSettingData != nullptr)
            m_scalarBarSettingData->readFromProjectFile(&_ScalarBarSettingDataEle.at(0).toElement(), isdiso);
        if (m_geometrySettingData != nullptr)
            m_geometrySettingData->readFromProjectFile(&_TDCMGeometrySettingDataEle.at(0).toElement(), isdiso);
        if (m_resultDataSettingData != nullptr)
            m_resultDataSettingData->readFromProjectFile(&_TDCMResultDataSettingDataEle.at(0).toElement().toElement(), isdiso);
        if (m_cubeAxesActorSettingData != nullptr)
            m_cubeAxesActorSettingData->readFromProjectFile(&_TDCMCubeAxesActorSettingDataeEle.at(0).toElement(), false, isdiso);
    }

    /*TDCMScalarBarSettingData::TDCMScalarBarSettingData(QObject* parent)
        : QObject(parent)
    {
    }

    void TDCMScalarBarSettingData::setScalarBarFontSize(int fontSize)
    {
        m_fontSize = fontSize;
    }

    int TDCMScalarBarSettingData::getScalarBarFontSize() const
    {
        return m_fontSize;
    }

    void TDCMScalarBarSettingData::setScalarBarMaxValue(double maxValue)
    {
        m_maxValue = maxValue;
    }

    double TDCMScalarBarSettingData::getScalarBarMaxValue() const
    {
        return m_maxValue;
    }

    void TDCMScalarBarSettingData::setScalarBarMinValue(double minValue)
    {
        m_minValue = minValue;
    }

    double TDCMScalarBarSettingData::getScalarBarMinValue() const
    {
        return m_minValue;
    }

    void TDCMScalarBarSettingData::setScalarBarAutoRange(bool isAutoRange)
    {
        m_isUseScalarBarAutoRange = isAutoRange;
    }

    bool TDCMScalarBarSettingData::getScalarBarAutoRange() const
    {
        return m_isUseScalarBarAutoRange;
    }

    void TDCMScalarBarSettingData::setScalarBarIsShowTitle(bool isShowTitle)
    {
        m_isShowTitle = isShowTitle;
    }

    bool TDCMScalarBarSettingData::getScalarBarIsShowTitle() const
    {
        return m_isShowTitle;
    }

    void TDCMScalarBarSettingData::setScalarBarTitleColor(QColor titleColor)
    {
        m_titleColor = titleColor;
    }

    QColor TDCMScalarBarSettingData::getScalarBarTitleColor() const
    {
        return m_titleColor;
    }

    void TDCMScalarBarSettingData::setScalarBarFontFamily(QString fontFamily)
    {
        m_fontFamily = fontFamily;
    }

    QString TDCMScalarBarSettingData::getScalarBarFontFamily() const
    {
        return m_fontFamily;
    }

    void TDCMScalarBarSettingData::setScalarBarTitle(QString title)
    {
        m_title = title;
    }

    QString TDCMScalarBarSettingData::getScalarBarTitle() const
    {
        return m_title;
    }

    void TDCMScalarBarSettingData::setScalarBarOriginalMinRange(double minValue)
    {
        m_scalarBarMinValueOriginal = minValue;
    }

    double TDCMScalarBarSettingData::getScalarBarOriginalMinRange() const
    {
        return m_scalarBarMinValueOriginal;
    }

    void TDCMScalarBarSettingData::setScalarBarOriginalMaxRange(double maxValue)
    {
        m_scalarBarMaxValueOriginal = maxValue;
    }

    double TDCMScalarBarSettingData::getScalarBarOriginalMaxRange() const
    {
        return m_scalarBarMaxValueOriginal;
    }*/

    TDCMGeometrySettingData::TDCMGeometrySettingData(QObject* parent)
        : QObject(parent)
    {
    }

    void TDCMGeometrySettingData::setGeometryTransparency(int transparency)
    {
        m_transparency = transparency;
    }

    int TDCMGeometrySettingData::getGeometryTransparency() const
    {
        return m_transparency;
    }

    QDomElement& TDCMGeometrySettingData::writeToProjectFile(QDomDocument* doc, QDomElement* element, bool isdiso)
    {
        QDomElement _TDCMGeometrySettingDataRoot = doc->createElement("TDCMGeometrySettingData");

        GlobalHelperInstance->createDomElement(doc, &_TDCMGeometrySettingDataRoot, "Transparency", QString::number(m_transparency));

        element->appendChild(_TDCMGeometrySettingDataRoot);

        return _TDCMGeometrySettingDataRoot;
    }

    void TDCMGeometrySettingData::readFromProjectFile(QDomElement* element, bool isdiso)
    {
        auto _TransparencyNodeList = element->elementsByTagName("Transparency");
        m_transparency = _TransparencyNodeList.item(0).toElement().text().toInt();

    }

    TDCMResultDataSettingData::TDCMResultDataSettingData(QObject* parent)
        : QObject(parent)
    {
    }

    void TDCMResultDataSettingData::setResultDataName(QString resultName)
    {
        m_resultName = resultName;
    }

    QString TDCMResultDataSettingData::getResultDataName() const
    {
        return m_resultName;
    }

    void TDCMResultDataSettingData::setResultDataTransparency(int transparency)
    {
        m_transparency = transparency;
    }

    int TDCMResultDataSettingData::getResultDataTransparency() const
    {
        return m_transparency;
    }

    void TDCMResultDataSettingData::setResultDataScaleFactor(double scaleFactor)
    {
        m_scaleFactor = scaleFactor;
    }

    double TDCMResultDataSettingData::getResultDataScaleFactor() const
    {
        return m_scaleFactor;
    }

    QDomElement& TDCMResultDataSettingData::writeToProjectFile(QDomDocument* doc, QDomElement* element, bool isdiso)
    {
        QDomElement _TDCMResultDataSettingDataRoot = doc->createElement("TDCMResultDataSettingData");

        GlobalHelperInstance->createDomElement(doc, &_TDCMResultDataSettingDataRoot, "ResultName", m_resultName);
        GlobalHelperInstance->createDomElement(doc, &_TDCMResultDataSettingDataRoot, "Transparency", QString::number(m_transparency));
        GlobalHelperInstance->createDomElement(doc, &_TDCMResultDataSettingDataRoot, "ScaleFactor", QString::number(m_scaleFactor));

        element->appendChild(_TDCMResultDataSettingDataRoot);

        return _TDCMResultDataSettingDataRoot;
    }

    void TDCMResultDataSettingData::readFromProjectFile(QDomElement* element, bool isdiso)
    {
        auto _ResultNameNodeList = element->elementsByTagName("ResultName");
        m_resultName = _ResultNameNodeList.item(0).toElement().text();
        auto _TransparencyNodeList = element->elementsByTagName("Transparency");
        m_transparency = _TransparencyNodeList.item(0).toElement().text().toInt();
        auto _ScaleFactorNodeList = element->elementsByTagName("ScaleFactor");
        m_scaleFactor = _ScaleFactorNodeList.item(0).toElement().text().toDouble();
    }

    TDCMCubeAxesActorSettingData::TDCMCubeAxesActorSettingData(QObject* parent)
        :QObject(parent)
    {
    }

    void TDCMCubeAxesActorSettingData::setVisibility(bool isVis)
    {
        m_isVisibility = isVis;
    }


    bool TDCMCubeAxesActorSettingData::getVisibility() const
    {
        return m_isVisibility;
    }

    QDomElement& TDCMCubeAxesActorSettingData::writeToProjectFile(QDomDocument* doc, QDomElement* element, bool isFormWindow, bool isdiso)
    {
        QString ElementName = "TDCMCubeAxesActorSettingData";
        if (isFormWindow)
        {
            ElementName = "TDCMCubeAxesActorSettingDataFromWindow";
        }

        QDomElement _TDCMCubeAxesActorSettingDataRoot = doc->createElement(ElementName);

        GlobalHelperInstance->createDomElement(doc, &_TDCMCubeAxesActorSettingDataRoot, "IsVisibility", QString::number(m_isVisibility));

        element->appendChild(_TDCMCubeAxesActorSettingDataRoot);

        return _TDCMCubeAxesActorSettingDataRoot;
    }

    void TDCMCubeAxesActorSettingData::readFromProjectFile(QDomElement* element, bool isFormWindow, bool isdiso)
    {
        auto _IsVisibilityNodeList = element->elementsByTagName("IsVisibility");
        m_isVisibility = (bool)_IsVisibilityNodeList.item(0).toElement().text().toInt();
    }
}
